package com.mzy.linear_struct.subject;

import com.mzy.linear_struct.utils.Utils;

import java.util.Arrays;

/**
 * @Author: mizy3
 * @Date: 2024/05/20/上午11:38
 * @Description:
 */
public class 移动0 {

    public static void moveZeroes(int[] nums) {
        // 1 2 0 3 12
        //   i
        // j

            int i = 0;
            int j = 0;

            for (i = 0; i < nums.length; i++) {
                if(nums[i] != 0){
                    swap(nums, i, j);
                    j++;
                }
            }
    }

    public static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1 ,2 ,0 ,3 ,12};

        moveZeroes(nums);

        System.out.println(Arrays.toString(nums));
    }
}
